package com.leejxx.health.controller;

import com.leejxx.health.common.MessageConst;
import com.leejxx.health.entity.PageResult;
import com.leejxx.health.entity.QueryPageBean;
import com.leejxx.health.entity.Result;
import com.leejxx.health.pojo.CheckGroup;
import com.leejxx.health.pojo.CheckItem;
import com.leejxx.health.service.CheckGroupService;
import com.leejxx.health.utils.RedisUtils;
import com.leejxx.health.vo.AddOrEditCheckGroupParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author LeeJx
 * @ClassName CheckGroupController
 * @Description TODO
 * @date 2020/12/31 18:09
 * @Version 1.0
 */
@RestController
@Slf4j
@RequestMapping("/checkGroup")
public class CheckGroupController {
    @DubboReference
    private CheckGroupService checkGroupService;
    @Autowired
    private RedisTemplate redisTemplate;
    @RequestMapping("/findByPage")
    public Result findByPage(@RequestBody QueryPageBean queryPageBean) {
        log.info("[检查组管理-分页查询]data:{}", queryPageBean);
        PageResult pageResult = checkGroupService.findByPage(queryPageBean);
        log.info("[检查组管理-分页查询]data:{}", pageResult);
        return new Result(true, MessageConst.QUERY_CHECKGROUP_SUCCESS, pageResult);
    }

    @RequestMapping("/add")
    public Result add(@RequestBody AddOrEditCheckGroupParam addOrEditCheckGroupParam) {
        log.info("[检查组管理-检查组添加]data:{}", addOrEditCheckGroupParam);
        checkGroupService.add(addOrEditCheckGroupParam.getCheckGroup(), addOrEditCheckGroupParam.getCheckItemIds());
        return new Result(true, MessageConst.ADD_CHECKGROUP_SUCCESS);
    }

    @RequestMapping("/findCheckItem")
    public Result findCheckItem() {
        log.info("[检查组管理-检查组添加回显检查项]");
        List<CheckItem> checkItems = checkGroupService.findCheckItem();
        log.info("[检查组管理-检查组添加回显检查项]data:{}", checkItems);
        return new Result(true, MessageConst.QUERY_CHECKGROUP_SUCCESS,checkItems);
    }

    @RequestMapping("/findById")
    public Result findById(Integer checkGroupId) {
        log.info("[检查组管理-检查组修改回显检查组和检查项]data:{}", checkGroupId);
        CheckGroup checkGroup = checkGroupService.findById(checkGroupId);
        log.info("[检查组管理-检查组修改回显检查组和检查项]data:{}", checkGroup);
        return new Result(true, MessageConst.QUERY_CHECKGROUP_SUCCESS,checkGroup);
    }

    @RequestMapping("/edit")
    public Result edit(@RequestBody AddOrEditCheckGroupParam addOrEditCheckGroupParam) {
        log.info("[检查组管理-检查组修改]data:{}", addOrEditCheckGroupParam);
        checkGroupService.edit(addOrEditCheckGroupParam.getCheckGroup(), addOrEditCheckGroupParam.getCheckItemIds());
        return new Result(true, MessageConst.EDIT_CHECKGROUP_SUCCESS);
    }
    @RequestMapping("/delete")
    public Result delete(Integer checkGroupId) {
        log.info("[检查组管理-检查组修改]data:{}", checkGroupId);
        checkGroupService.delete(checkGroupId);
        return new Result(true, MessageConst.DELETE_CHECKGROUP_SUCCESS);
    }
}
